/*
 *    Copyright (C) 2011-2012 Hai Bison
 *
 *    See the file LICENSE at the root directory of this project for copying
 *    permission.
 */

/*
 * DialogAbout.java
 *
 * Created on Sep 25, 2011, 10:33:41 PM
 */
package group.pals.mailgate;

import group.pals.mailgate.utils.Utils;
import group.pals.utils.sys.SysUtils;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JTextArea;

/**
 *
 * @author Hai Bison
 */
public class DialogAbout extends javax.swing.JDialog {

    private final Utils TheUtils;
    private final group.pals.mailgate.ui.Utils UIUtils;

    /** Creates new form DialogAbout */
    public DialogAbout(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        setLocationRelativeTo(parent);

        this.TheUtils = Utils.getInstance();
        this.UIUtils = group.pals.mailgate.ui.Utils.getInstance();

        initUI();
        initActions();
    }

    private void initUI() {
        group.pals.utils.ui.Utils.setWindowCenterScreen(this, 40);
        setResizable(false);
        setTitle("About...");

        labelMainLogo.setIcon(TheUtils.getIcon(80));
        labelMainLogo.setText(null);

        JTextArea[] txtFields = {txtAbout, txtDonation};
        final int Inset = 8;
        for (JTextArea txt : txtFields) {
            txt.setEditable(false);
            txt.setLineWrap(true);
            txt.setWrapStyleWord(true);
            txt.setComponentPopupMenu(UIUtils.getEditorPopupMenu());
            txt.setMargin(new Insets(Inset, Inset, Inset, Inset));
        }

        Font font = txtAbout.getFont();
        txtAbout.setFont(new Font(Font.MONOSPACED, font.getStyle(), font.getSize()));
        txtAbout.setText(TheUtils.getAboutText());
        txtAbout.setCaretPosition(0);

        txtDonation.setText("If you find this application useful, please consider to make a donation."
                + " Your donation will help me on developing more better-free applications.\n\n"
                + "You could click on below button to goto my donation webpage on PayPal.\n\n"
                + "Sincerely,\n"
                + "Haiti");
    }

    private void initActions() {
        buttonCool.setAction(new AbstractAction("Cool") {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });

        buttonGotoPaypalDonationPage.setAction(new AbstractAction("Donate via Paypal") {

            public void actionPerformed(ActionEvent e) {
                try {
                    SysUtils.openUrl(Utils.PaypalDonationURL);
                } catch (Exception ex) {
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        tabbedPaneMain = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAbout = new javax.swing.JTextArea();
        labelMainLogo = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtDonation = new javax.swing.JTextArea();
        buttonGotoPaypalDonationPage = new javax.swing.JButton();
        buttonCool = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        txtAbout.setColumns(20);
        txtAbout.setRows(5);
        jScrollPane1.setViewportView(txtAbout);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(jScrollPane1, gridBagConstraints);

        labelMainLogo.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
        jPanel1.add(labelMainLogo, gridBagConstraints);

        tabbedPaneMain.addTab("About...", jPanel1);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        txtDonation.setColumns(20);
        txtDonation.setRows(5);
        jScrollPane2.setViewportView(txtDonation);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        jPanel2.add(jScrollPane2, gridBagConstraints);

        buttonGotoPaypalDonationPage.setText("jButton1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
        jPanel2.add(buttonGotoPaypalDonationPage, gridBagConstraints);

        tabbedPaneMain.addTab("Donation  :-)", jPanel2);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
        getContentPane().add(tabbedPaneMain, gridBagConstraints);

        buttonCool.setText("jButton1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LAST_LINE_END;
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
        getContentPane().add(buttonCool, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents
//  /**
//   * @param args the command line arguments
//   */
//  public static void main(String args[]) {
//    /* Set the Nimbus look and feel */
//    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//     */
//    try {
//      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//        if ("Nimbus".equals(info.getName())) {
//          javax.swing.UIManager.setLookAndFeel(info.getClassName());
//          break;
//        }
//      }
//    } catch (ClassNotFoundException ex) {
//      java.util.logging.Logger.getLogger(DialogAbout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//    } catch (InstantiationException ex) {
//      java.util.logging.Logger.getLogger(DialogAbout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//    } catch (IllegalAccessException ex) {
//      java.util.logging.Logger.getLogger(DialogAbout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//      java.util.logging.Logger.getLogger(DialogAbout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//    }
//    //</editor-fold>
//
//    /* Create and display the dialog */
//    java.awt.EventQueue.invokeLater(new Runnable() {
//
//      public void run() {
//        DialogAbout dialog = new DialogAbout(new javax.swing.JFrame(), true);
//        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//          @Override
//          public void windowClosing(java.awt.event.WindowEvent e) {
//            System.exit(0);
//          }
//        });
//        dialog.setVisible(true);
//      }
//    });
//  }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCool;
    private javax.swing.JButton buttonGotoPaypalDonationPage;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelMainLogo;
    private javax.swing.JTabbedPane tabbedPaneMain;
    private javax.swing.JTextArea txtAbout;
    private javax.swing.JTextArea txtDonation;
    // End of variables declaration//GEN-END:variables
}
